/**
 * Smart City use case October 2012 
 */
package com.orange.smartcity.android.activity;


import static com.orange.smartcity.android.SmartCityCommon.*;

import com.orange.smartcity.android.R;
import com.orange.smartcity.android.tools.ApplicationMenuUtils;
import com.orange.smartcity.android.tools.PreferencesUtils;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CheckBox;

/**
 * @author FAIROUZ OUBENALI
 *
 */
public class Settings extends Activity implements OnPreferenceChangeListener {
	private CheckBox mShopCheckBox;
	
	/**
	 * Called when the activity is first created. Responsible for initializing
	 * the UI.
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Log.i(SETTING_ACTIVITY_TAG, "**** Settings UI lunched ****");
		getFragmentManager().beginTransaction()
				.replace(android.R.id.content, new PreferencesUtils()).commit();
		
		

	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		// super.onActivityResult(requestCode, resultCode, data);

		/*
		 * To make it simple, always re-load Preference setting.
		 */

		getPrefs();
	}
	

	
	private void getPrefs() {
		SharedPreferences mySharedPreferences = PreferenceManager
				.getDefaultSharedPreferences(this);

		boolean my_shop_preference = mySharedPreferences.getBoolean("shop",
				false);
		mShopCheckBox.setChecked(my_shop_preference);
		Log.i(SETTING_ACTIVITY_TAG, "shop was selected *** " + my_shop_preference);

	}
	/*
	 * ==========================================================================
	 * = * menu * *
	 * ======================================================================
	 */

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		ApplicationMenuUtils.onPrepareOptionsMenu(this, menu);
		return super.onPrepareOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		ApplicationMenuUtils.onOptionsItemSelected(this, item);
		return true;
	}
	
	/*
	 * ==========================================================================
	 * = * listener preference * *
	 * ======================================================================
	 */

	public boolean onPreferenceChange(Preference preference, Object newValue) {
		// TODO Auto-generated method stub
		return false;
	}

}